using System.Collections;
using DimensionsHelper.Common.Contracts;
using DimensionsHelper.Common.Contracts.Services;
using Xunit.Abstractions;

namespace TestBasic;

public class TestBase(ITestOutputHelper helper) : IReportService
{

    protected readonly ITestOutputHelper Output = helper;

    public void Directory(string localDirectory)
    {
        Output.WriteLine($"Local directory: {localDirectory}");
    }

    public void Directory(string localDirectory, string format, params object?[] args)
    {
        Output.WriteLine("{0}: {1}", string.Format(format, args), localDirectory);
    }


    public void Error(string format, params object?[] args)
    {
        Output.WriteLine(format, args);
    }

    public void Log(string format, params object?[] args)
    {
        Output.WriteLine(format, args);
    }

    public void Log(ReportLevel level, string format, params object?[] args)
    {
        Output.WriteLine(format, args);
    }

    public void Progress(double progress)
    {

    }

    public void Progress(double progress, string format, params object?[] args)
    {
        // Output.WriteLine(format, args);
    }

    public void Warn(string format, params object?[] args)
    {
        Output.WriteLine(format, args);
    }

    public IProgressEnumerable<T> WithProgress<T>(IEnumerable<T> source, int length, Func<T, double, string>? messageGetter)
    {
        return new ProgressEnumerable<T>(source);
    }


    private readonly struct ProgressEnumerable<T>(IEnumerable<T> source) : IProgressEnumerable<T>
    {
        public Func<T, double, string>? MessageGetter => null;

        public IEnumerator<T> GetEnumerator() => source.GetEnumerator();
        
        IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
    }
}